<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <table border="1" style="text-align: center;color: red">
    <tr><th>ID</th><th>商品标题</th><th>商品价格(￥)</th><th>商品库存</th><th>操作</th></tr>
    <tr v-for="p in arr">
      <td>{{p.id}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.num}}</td>
      <td>
        <!--属性绑定需要加:-->
        <a :href="'/update.html?id='+p.id">修改</a>
        <a href="javascript:void(0)" @click="del(p.id)">删除</a></td>
    </tr>

  </table>
</div>
<!--引入axios和vue框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
    let v = new Vue({
            el:"body>div",
            data:{
              arr:[]
               /*arr:[{id:1,title:"苹果",price:8.90,num:200},{id:2,title:"葡萄",price:11.90,num:100}]*/
            },
            methods: {
              del(id){
                if (confirm("您确认删除此商品吗？")) {
                  axios.get("/delete?id=" + id).then(function (response) {
                    location.reload();/*刷新页面*/
                  });
                }
              }

            },
      created: function () {
        axios.get("/select").then(function (response) {
          v.arr = response.data;
        });
      }
    })
</script>
</body>
</html>